#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
    int n,m,a,b;
    cin>>n>>m>>a>>b;
    int x,y;
    x=max(a-1,n-a);
    y=max(b-1,m-b);
    int tn=n,tm=m;
    n-=x,tm-=y;
    int hc=1,lc=1;
    while(n!=1)
    {
        if(n%2)n>>=1,n++;
        else n>>=1;
        hc++;
    }
    while(m!=1)
    {
        if(m%2)m>>=1,m++;
        else m>>=1;
        hc++;
    }
    while(tn!=1)
    {
        if(tn%2)tn>>=1,tn++;
        else tn>>=1;
        lc++;
    }
    while(tm!=1)
    {
        if(tm%2)tm>>=1,tm++;
        else tm>>=1;
        lc++;
    }
    cout<<min(hc,lc)<<endl;
}
signed main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    int T=1;
    cin>>T;
    while(T--)
    {
       solve();
    }
    return 0;
}